package tpdisenio2009.model;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtils {

    private static SessionFactory sessionFactory;
    private static Session session;

    static {
        sessionFactory = new AnnotationConfiguration().addPackage("tpdisenio2009.model.beans").configure("/tpdisenio2009/model/hibernate.cfg.xml").buildSessionFactory();
        session = sessionFactory.openSession();
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static Session openSession() {
        return sessionFactory.openSession();
    }

    public static Session getCurrentSession() {
        return session;
    }

    public static void close() {
        if (sessionFactory != null) {
            sessionFactory.close();
        }
        sessionFactory = null;
    }
}
